package com.nebula.salary.common.utils;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Locale;

/**
 * NumberFormat工具类
 *
 * @author codex
 * @since 2022-03-26
 */
public class NumberFormatUtil {
    
    /**
     * 根据入参转为相应的格式
     */
    public static String numberToMoney(BigDecimal number, Locale locale) {
        NumberFormat nf = NumberFormat.getCurrencyInstance(locale);
        return nf.format(number);
    }
    
    /**
     * 转为人民币形式
     */
    public static String numberToRmb(BigDecimal number) {
        return numberToMoney(number, Locale.CHINA);
    }
    
    /**
     * 用逗号间隔数字
     */
    public static String numberToString(BigDecimal number) {
        NumberFormat nf = NumberFormat.getInstance();
        return nf.format(number);
    }
}
